using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

/// <summary>
/// This class must be the base class for all the pages that need to use the multi-language support
/// </summary>
public class PageBase : System.Web.UI.Page
{
    /// <summary>
    /// Initialize de culture choosen by the user
    /// </summary>
    protected override void InitializeCulture()
    {
        if (!IsPostBack)
        {
            DefineCulture();
            base.InitializeCulture();
        }
    }

    /// <summary>
    /// Set the culture choosen by the user
    /// </summary>
    /// <remarks>
    /// If the culture was not choosen, the default language from de user's browser is defined
    /// </remarks>
    public static void DefineCulture()
    {
        if (SelectedCulture == null)
        {
            SelectedCulture = new CultureInfo(HttpContext.Current.Request.UserLanguages[0]);
        }

        System.Threading.Thread.CurrentThread.CurrentCulture = SelectedCulture;
        System.Threading.Thread.CurrentThread.CurrentUICulture = SelectedCulture;
    }

    /// <summary>
    /// Get or set the culture to use
    /// </summary>
    public static CultureInfo SelectedCulture
    {
        get
        {
            return (CultureInfo)HttpContext.Current.Session["SelectedCulture"];
        }
        set
        {
            HttpContext.Current.Session["SelectedCulture"] = value;
        }
    }
}
